"""
-*- coding: utf-8 -*-
@File  : samm_mat2jpg.py
@author: ZhenyuYang
@Time  : 2023/04/06 9:24
"""
import os
import cv2
import scipy.io as scio

if not os.path.exists("../data/SAMM"):
    os.mkdir("../data/SAMM")
video_list = os.listdir("../data/SAMM_mat")
print(video_list)
for video in video_list:
    sub = int(video.split("_")[0])
    video_name = video.split(".")[0]
    if not os.path.exists("../data/SAMM/{}".format(sub)):
        os.mkdir("../data/SAMM/{}".format(sub))
    if not os.path.exists("../data/SAMM/{}/{}".format(sub, video_name)):
        os.mkdir("../data/SAMM/{}/{}".format(sub, video_name))
    frames = scio.loadmat("../data/SAMM_mat/{}".format(video))['tempImg']
    for frame_index in range(frames.shape[2]):
        frame = frames[:, :, frame_index]
        # cv2.imshow('Frame', frame)
        # cv2.waitKey(0)
        cv2.imwrite("../data/SAMM/{}/{}/{:05d}.jpg".format(sub, video_name, frame_index+1), frame)
